#include <gtest/gtest.h>
#include "../mqserver/mq_queue.hpp"

mq_zxws::MsgQueueManager::ptr mqmp;

class ExchangeTest: public testing::Environment
{
public:
    virtual void SetUp()override{
        mqmp = std::make_shared<mq_zxws::MsgQueueManager>("./data/meta.db");
    }
    virtual void TearDown()override{
        mqmp->clear();
    }
};

// TEST(queue_test, insert_test){
//     std::unordered_map<std::string, std::string> m = {{"k1","v1"}};
//     mqmp->declareQueue("queue1",true, false, false, m);
//     mqmp->declareQueue("queue2",true, false, false, m);
//     mqmp->declareQueue("queue3",true, false, false, m);
//     mqmp->declareQueue("queue4",true, false, false, m);
//     ASSERT_EQ(mqmp->size(), 4);
// }


// TEST(queue_test, select_test){
//     auto it = mqmp->selectOne("queue2");
//     ASSERT_EQ(it->name, "queue2");
//     ASSERT_EQ(it->exclusive, false);
//     ASSERT_EQ(it->durable, true);
//     ASSERT_EQ(it->auto_delete, false);
//     ASSERT_EQ(it->getArgs(), std::string("k1=v1&"));
// }


TEST(queue_test, delete_test){
    mqmp->deleteQueue("queue2");
    auto it = mqmp->selectOne("queue2");
    ASSERT_EQ(it.get(), nullptr);
    ASSERT_EQ(mqmp->exists("queue2"), false);
}

int main(int argc, char*argv[])
{
    testing::InitGoogleTest(&argc, argv);
    testing::AddGlobalTestEnvironment(new ExchangeTest);
    int res = RUN_ALL_TESTS();
    return 0;
}